home *** CD-ROM | disk | FTP | other *** search
/ ShareWare OnLine 2 / ShareWare OnLine Volume 2 (CMS Software)(1993).iso / games2 / probo30.zip / SFIGHTER.PR < prev    next >
Text File  |  1993-02-20  |  4KB  |  118 lines

  1.   PROCEDURE SFighter;  {Stealth Fighter}
  2.   {
  3.    Author: David Malmberg
  4.  
  5.    Strategy:  Move slowly around the field -- bouncing off of walls,
  6.    obstructions, and other robots -- as necessary.  If you find a foe,
  7.    take a shot and keep improving aim and shooting until foe is
  8.    lost from sights.  Then move sights (scanning) to adjacent target
  9.    area.
  10.  
  11.    When robot incurrs damage, raise cloak and move away.  Keep cloak
  12.    raised until robot has not had any damage for at least 3000 cycles.
  13.   }
  14.  
  15. (* Below are the SFighter options as specified in the SFIGHTER.CFG file
  16.  
  17. Radar := 2;          {Maximum range for robot's scanner -- 600 meters}
  18. Fuel := 2;           {Maximum fuel for robot -- 1250 jiggers}
  19. Engine := 0;         {Type of engine for robot -- Economy}
  20. Armor := 0;          {Type of Armor for robot -- Light}
  21. Warheads := 1;       {Type of Missile for robot -- Normal -- 700 meter range}
  22. Bombs := 0;          {Determines the number of Bombs for robot}
  23. Shielding := 0;      {Default -- Robot has Shielding}
  24. Cloaking := 5;       {Default -- Robot has Cloaking}
  25. Repairing := 0;      {Default -- Robot has NO Repair Kit}
  26.  
  27. *)
  28.  
  29.   VAR { SFighter "Global" variables }
  30.  
  31.     Angle, { Scanning angle }
  32.     Range, { Scanning range to foe -- hopefully! }
  33.     Last_Damage, { Robot's Last damage value }
  34.     D_Speed, { Robot's desired speed }
  35.     D_Heading, { Robot's desired heading }
  36.     LastTime, { Last Time cycles were measured }
  37.     Delta          : Integer; { Scanning arc }
  38.  
  39.  
  40.     PROCEDURE Bounce;
  41.       { If stopped, then move away at an angle.  Designed to allow
  42.         robot to "bounce" off of walls, obstructions and other robots. }
  43.     BEGIN
  44.       IF Speed = 0
  45.         THEN BEGIN
  46.           D_Heading := D_Heading + 120; { Bounce off at an angle }
  47.           Drive(D_Heading, D_Speed);
  48.         END;
  49.     END; {Bounce}
  50.  
  51.  
  52.     FUNCTION Hurt  : Boolean;
  53.       { Checks if Robot has incurred any new damage. }
  54.     VAR Curr_Damage : Integer;
  55.       Answer         : Boolean;
  56.     BEGIN
  57.       Curr_Damage := damage;
  58.       Answer := (Curr_Damage > Last_Damage);
  59.       Last_Damage := Curr_Damage;
  60.       IF Answer THEN LastTime := Time;
  61.       Hurt := Answer;
  62.     END; {Hurt}
  63.  
  64.  
  65.     PROCEDURE Aim(VAR Ang : Integer; VAR Arc : Integer);
  66. {
  67.  Improve aim by doing a binary search of the target area.
  68.  I.E., divide the target area in two equal pieces and redefine
  69.  the target area to be the piece where the foe is found.
  70.  If the foe is not found, expand the search area to the
  71.  maximum arc of plus or minus 10 degrees.
  72. }
  73.     BEGIN
  74.       Arc := Arc DIV 2; { Divide search area in two. }
  75.       IF scan(Ang-Arc, Arc) <> 0 { Check piece "below" target angle. }
  76.         THEN Ang := Ang-Arc { If foe found, redefine target angle. }
  77.         ELSE IF scan(Ang+Arc, Arc) <> 0 { Check piece "above" target angle. }
  78.           THEN Ang := Ang+Arc { If foe found, redefine target angle. }
  79.           ELSE Arc := 10;
  80.       { Foe not found in either piece, expand search area to maximum arc. }
  81.     END; {Aim}
  82.  
  83.   BEGIN {SFighter Main}
  84.     Angle := Angle_To(500, 500);
  85.     D_Heading := Angle;
  86.     D_Speed := 50;
  87.     { Start scanning for foes and moving to center of field. }
  88.     LowerCloak; { Start off with Cloak DOWN! }
  89.     LastTime := Time;
  90.     REPEAT { Until Dead or Winner }
  91.       Bounce; { If stopped, move off at angle }
  92.       IF Fuel < 250 THEN LowerCloak;
  93.       IF NOT Hurt {If not hurt and no damage for 3000 cycles}
  94.         THEN IF (Time > (LastTime + 3000))
  95.           THEN BEGIN {Safe to lower cloak and slow down}
  96.             LowerCloak;
  97.             D_Speed := 50;
  98.           END;
  99.       Delta := 10; { Start with widest scanning arc. }
  100.       Range := scan(Angle, Delta);
  101.       WHILE (Range > 40) AND (ObjectScanned = Enemy) DO
  102.         { Must be far enough away to avoid self-damage. }
  103.         BEGIN
  104.           Aim(Angle, Delta); { Improve aim. }
  105.           Cannon(Angle, Range); { Fire!! }
  106.           Range := scan(Angle, Delta); { Is foe still in sights? }
  107.         END;
  108.       Angle := Angle+20; { Look in adjacent target area. }
  109.       IF Hurt THEN { Raise cloak and flee! }
  110.         BEGIN
  111.           IF Fuel > 250 THEN RaiseCloak;
  112.           D_Heading := Angle + 180; { Run away from foe! }
  113.           D_Speed := MaxSpeed;
  114.           Drive(D_Heading, D_Speed);
  115.         END;
  116.     UNTIL Dead OR Winner;
  117.   END; {SFighter Main}
  118.